<template>
	<view class="discount page bgf5">
		<view @click="openShopPicker" class="flex flexC bold6 bgff px15" >
			<text class="c00 ellipsis1 py6 pr10">{{selectShop.name || '---'}}</text>
			<image class="down" src="/static/img/icon/down_nor.png" mode="widthFix"></image>
		</view>

		<group-coupon ref="groupCoupon" @refresh="refresh" ></group-coupon>
		<view class="add r50 bged aliC" @click="clickAdd">添加</view>

		<!-- 店铺选择 -->
		<uni-popup ref="shopPicker" type="bottom">
			<shop-list  @search="search" :list="list" @onSelectShop="onSelectShop" @close="onClose"></shop-list>
		</uni-popup>
		
		
	</view>
</template>

<script>
	const statusBar = uni.getSystemInfoSync().statusBarHeight + 10;
	export default {
		data() {
			return {
				statusBar,
				currentTab: 0,
				list: [],
				couponList:[],
				selectShop: null,
				keyword: "",
				isSearch: false,
			};
		},

		onLoad(option) {

			if(option.selectShop != ''){
				this.selectShop = JSON.parse(option.selectShop);
				this.$refs.groupCoupon.getData(this.selectShop);
				
			}


		},
		onShow() {
			this.getShopList();
			
		},
		methods: {
			
			clickAdd(){
				uni.navigateTo({
					url:'../coupon/couponAdd?selectShop='+JSON.stringify(this.selectShop)
				})
			},

			search(e) {

				this.keyword = e;
				this.getShopList();
				this.isSearch = true;
				console.info("=====search=====" + e);
			},
			
			refresh(){
				console.info("====refresh===");
				this.$refs.groupCoupon.getData(this.selectShop);
			},




			// 选择店铺
			onSelectShop(item) {
				this.selectShop = item;
				this.isSearch = false;
				this.onClose();
				this.$refs.groupCoupon.getData(this.selectShop);
			

			},
			getShopList() {
				let param = {
					keyword: this.keyword
				};
				let that = this;
				this.$api.getShopList(param).then(res => {
					console.info(JSON.stringify(res));
					if (res.code == 1) {
						that.list = res.data;
						this.$refs.groupCoupon.getData(this.selectShop);
						
					
					} else {

					}
				})
			},


			openShopPicker() {
				this.$refs.shopPicker.open();
			},
			onClose() {
				this.$refs.shopPicker.close();
			}
		}
	}
</script>

<style lang="scss">
	.discount {
		.icon {
			width: 38rpx;
		}

		.down {
			width: 20rpx;
			height: 20rpx;
		}

		.ellipsis1 {
			max-width: 200rpx;
		}
		.add {
			position: fixed;
			bottom: 100px;
			right: 10rpx;
			width: 80rpx;
			height: 80rpx;
			line-height: 80rpx;
			border: 2rpx solid #418FF4;
		}

		.active {
			position: relative;

			&::after {
				content: '';
				width: 120rpx;
				height: 8rpx;
				background-color: #576DAB;
				border-radius: 8rpx;
				position: absolute;
				bottom: 0;
				left: calc(50% - 60rpx);
			}
		}
	}
</style>
